package com.example.springboot.controller;

import com.example.springboot.vo.ReqVO;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试restful请求
 * <p> GET、POST等
 * <p>
 * @author Zhang.Z
 * @version 2025-09-20
 */
@RestController
public class HelloWebController {

    @RequestMapping("/hello")
    public String requestTest() {

        return "hello spring boot";
    }


    /**
     * get方式,
     * 指定返回编码格式 UTF-8
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
    public String getTest(@RequestParam String param) {

        return "接收到的参数是 = " + param;
    }


    /**
     * post方式， form data传参
     */
    @RequestMapping(value = "/post", method = RequestMethod.POST)
    public String postTest(@RequestParam(value = "pageNo") Integer pageNo,
                           @RequestParam(value = "pageSize") Integer pageSize) {

        return "pageNo: " + pageNo + ",pageSize: " + pageSize;
    }

    /**
     * post测试，json传参
     */
    @RequestMapping(value = "/post/json")
    public ReqVO postJSON(@RequestBody ReqVO reqVO) {

        return reqVO;
    }
}
